function Term(value, desc) {
  var source = value.lasModify ? value : null;
	
  this.id = source && source.id ? source.id : (new Date()).getTime();
	this.value = source ? source.value : value; // String.
	this.desc = source ? source.desc : []; // Array of general info or translation or explanation of the meaning
	this.repeatCount = source ? source.repeatCount : 0; // Amount of actual display
	this.successCount = source ? source.successCount : 0; // Amount of successfully tested terms
	this.lasModify = source ? new Date(source.lasModify) : new Date(); // Time when this term was used
	this.isReadyToUse = source ? source.isReadyToUse : false;
	
	
	// Default actions on instance creation
	if (desc) {
		this.desc.push(desc); // Adding first description while creating an instance
		this.isReadyToUse = true;
	}	
	return this;
}

Term.prototype = {
  addDesc : function(desc) {
    if ($.trim(desc)) {
      this.desc.push(desc);
      this.isReadyToUse = true;
    } 
  },
  
  changeDesc : function(index, newDesc) {
    if ($.trim(desc)) {
      this.desc[index] = newDesc;
      this.isReadyToUse = true;
    }
  },
  
  toString : function() {
    return this.value;
  },
  
  allDescsToString : function() {
    var str = '';
    for (var i = 0; i < this.desc.length; i++) {
      if (i != (this.desc.length -1)) {
        str += ', ';
      }
      str += this.desc[i];
      
    }
    return str;
  },
  
  haveDescription : function(desc) {
    for (var i = 0; i < this.desc.length; i++) {
      if (this.desc[i] == desc)
        return true;
    }
    return false;
  },
  
  deleteDescription : function(index) {
    this.desc.splice(index, 1);
    this.isReadyToUse = this.desc.length > 0; 
  },
  
  getRandomDescription : function() {
    return this.desc[Math.floor(Math.random()*this.desc.length)];
  }
}
